/**
 * Created by jijin on 2017/7/22.
 *
 * IOS底部菜单栏
 */
import React, { Component } from 'react';
import {
  View,
  TabBarIOS
} from 'react-native';
import MenuItem from './ios/menu-item';

export default class Menu extends Component {
  constructor(props) {
    super(props);
    this.state = {
      selectedItem: props.initialEntry || props.entries[0].id
    }
  }

  _onPress = (id) => {
    this.setState({selectedItem: id});
  };

  render() {
    let {entries} = this.props;
    return (
      <TabBarIOS {...this.props}>
        {
          entries.map(entry => (
            <MenuItem
              key={entry.id}
              selected={entry.id === this.state.selectedItem}
              {...entry}
              onPress={this._onPress}>
              {entry.element}
            </MenuItem>
          ))
        }
      </TabBarIOS>
    )
  }
}
